package com.ljy.my_study.leetcode.LRU缓存机制;

import java.util.*;

/**
 * @author lijunying
 * @date 2021/11/22 11:16
 */
public class LRUCache extends LinkedHashMap<Integer,Integer>{

    private int capacity=0;

    public LRUCache(int capacity) {
        super(capacity,0.75F,true);
        this.capacity=capacity;
    }

    public int get(int key) {
        Integer value=super.get(key);
        return value==null?-1:value;
    }

    public void put(int key, int value) {
        super.put(key,value);
    }

    @Override
    protected boolean removeEldestEntry(Map.Entry eldest) {
        return size() > capacity;
    }
}
